<?php
/*
 * Created on 02.10.2007 by Nikolai Plath..
 *
 * * @file:bindex.helper.php
 */
// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );

/**
 * @param int $id
 * @return object BIndex
 */
function getBIndexFromID ( $id )
{
	global $database;
	$query = "SELECT * FROM #__bindex_items_data" .
				"\n WHERE id_item = '" . $id . "'";
		$database->setQuery( $query );
		$b = $database->loadObjectList();
debugQuery($query);
	return ( $b );
} //function
	
	/**
	 * @return object - Bereiche
	 */
	function getBereiche ()
	{
		global $database;
		$query = "SELECT `id` FROM `#__bindex_bereiche`";
		$database->setQuery($query);
		$ret = $database->loadObjectList();

		return $ret;
	} //function
	
	/**
	 * @return object - Staedte
	 */
	function getStaedte ()
	{
		global $database;
		$query = "SELECT `id` FROM `#__bindex_staedte`";
		$database->setQuery($query);
		$ret = $database->loadObjectList();
		return $ret;
	} //function

	/**
	 * @param int - id Bereich
	 * @return object Staedte
	 */
	function getStaedteFromBereichID( $id )
	{
		global $database;
		$query = "SELECT `id` FROM `#__bindex_staedte`" .
				"\n WHERE `id_bereich` = '{$id}'";
		$database->setQuery($query);
		$ret = $database->loadObjectList();
		return $ret;
	} //function

	
	/**
	 * @param int $id_stadt
	 * @return obj Bereich
	 */
	function getBereichFromIDstadt ( $id_stadt )
	{
		global $database;
global $DBG;
		$b = NULL;
		$ret = NULL;
		$query = "SELECT `id_bereich`" .
				"\n FROM #__bindex_staedte" .
				"\n WHERE `id` = '".$id_stadt."'" .
						"\n AND `published` = '1'";
		$database->setQuery($query);
		$database->loadObject($b);
$DBG->query($query);
$DBG->out($b);
		$query = "SELECT * FROM #__bindex_bereiche" .
				"\n WHERE `id` = '".$b->id_bereich."'";
		$database->setQuery($query);
		$database->loadObject($ret);
$DBG->query($query);
$DBG->out($ret);
		return( $ret ) ? $ret : NULL;
	} //function
	
	/**
	 * @param int $id_bereich
	 * @param string $language_code
	 * @return string - value of "Bereich"
	 */
	function getValueBereich ( $id_bereich, $language_code )
	{
		global $database;
		$q = "SELECT `value`" .
			"\n FROM `#__bindex_bereiche_data`" .
			"\n WHERE `id_bereich` = '$id_bereich'" .
			"\n AND `language` = '$language_code'".
			"\n LIMIT 1";
		$database->setQuery($q);
		$v = $database->loadResult();
		return $v;
	} //function
	
	/**
	 * @param int $id - stadt
	 * @param str $language_code
	 * @return string - value of "Stadt"
	 */
	function getValueStadt ( $id, $language_code )
	{
		global $database;
//global $DBG;
		$query = "SELECT `value`" .
			"\n FROM `#__bindex_staedte_data`" .
			"\n WHERE `id_stadt` = '$id'" .
			"\n AND `language` = '$language_code'";
		$database->setQuery($query);
		$v = $database->loadResult();
//$DBG->query($query);
		return $v;
	} //function
	
	/**
	 * 
	 */
	function getValueStadtOrDefault ( $id, $language_code )
	{
		global $biConfig;
		$string = getValueStadt ( $id, $language_code );
		if( !$string ) $string = getValueStadt ( $id, $biConfig->ini_language );
		
		return $string;
	} //function
	/**
	 * @return bol access ?
	 */
	function canEdit ()
	{
		global $my;

		return( $my->gid > 1 ) ? TRUE : FALSE;
	} //function
	
	function getLanguageISO( $codeLangName="" ) {
		global $database;
		if ($codeLangName != "" ) {
			$database->setQuery( "SELECT iso FROM #__languages WHERE active=1 and code = '$codeLangName'order by ordering" );
			$langISO = $database->loadResult(false);
		}

		return $langISO;
	} //function
	
	function bi_is_writeable ( $path )
	{
		$ret = '<span style="color: ';
		$ret .= ( is_writable( $path ) ) ?  'green">'.BI_WRITEABLE : 'red">'.BI_NOT_WRITEABLE;
		$ret .= '</span>';

		return $ret;
	} //function


/**
 * TEST
 * TEST
 * TEST...
 * 
 */


function test_xgmap ()
{
	global $mainframe;
	global $biConfig;
//	include($biConfig->absolutePath.'/'.$biConfig->AppPath.'includes/js/gmap.js');
			$basepath = $biConfig->liveSite.'/components/com_bindex/includes/js/';
		#load JS
		
		$mainframe->addCustomHeadTag('<script type="text/javascript" src="'.$basepath.'gmap.js"></script>');
	
	$karte = new xgmap($biConfig->GMapKey);
	
	$mainframe->addCustomHeadTag($karte->headjs($biConfig->GMapKey,true));
	?>
	<div style="background-color:#666666;color:#FF0000;" align = "center">
<?php
$karte->mapdiv('600', '600');
?>
</div>
<?php
$karte->bodyjs();
$karte->map(6,'49.980067','10.8731',"normal",5,9);





$karte->mapMarker('52.5','13','dash.png');
$karte->mapMarker('48','11','cancel.png');





$karte->markend();



} //function

function test_ajax ()
{
		global $mainframe;
	global $biConfig;
//	include($biConfig->absolutePath.'/'.$biConfig->AppPath.'includes/js/gmap.js');
			$basepath = $biConfig->liveSite.'/components/com_bindex/includes/js/';
		#load JS
		
		$mainframe->addCustomHeadTag('<script type="text/javascript" src="'.$basepath.'ajax.js"></script>');
	echo '<div id="testtest" width="200px" height="200px"></div>';
	echo "<a href=\"javascript: callAHAH('index.php', 'testtest', 'aaa', 'bbb')\">hallo</a>";
} //function

function test_popup()
{
?>
<script language="JavaScript1.2">
//Popup Box- By Jim Silver @ jimsilver47@yahoo.com

var ns4=document.layers
var ie4=document.all
var ns6=document.getElementById&&!document.all

//drag drop function for NS 4////
/////////////////////////////////

var dragswitch=0
var nsx
var nsy
var nstemp

function drag_dropns(name){
if (!ns4)
return
temp=eval(name)
temp.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP)
temp.onmousedown=gons
temp.onmousemove=dragns
temp.onmouseup=stopns
}

function gons(e){
temp.captureEvents(Event.MOUSEMOVE)
nsx=e.x
nsy=e.y
}
function dragns(e){
if (dragswitch==1){
temp.moveBy(e.x-nsx,e.y-nsy)
return false
}
}

function stopns(){
temp.releaseEvents(Event.MOUSEMOVE)
}

//drag drop function for ie4+ and NS6////
/////////////////////////////////


function drag_drop(e){
if (ie4&&dragapproved){
crossobj.style.left=tempx+event.clientX-offsetx
crossobj.style.top=tempy+event.clientY-offsety
return false
}
else if (ns6&&dragapproved){
crossobj.style.left=tempx+e.clientX-offsetx
crossobj.style.top=tempy+e.clientY-offsety
return false
}
}

function initializedrag(e){
crossobj=ns6? document.getElementById("showimage") : document.all.showimage

var firedobj=ns6? e.target : event.srcElement
var topelement=ns6? "HTML" : "BODY"

while (firedobj.tagName!=topelement&&firedobj.id!="dragbar"){
firedobj=ns6? firedobj.parentNode : firedobj.parentElement
}

if (firedobj.id=="dragbar"){
offsetx=ie4? event.clientX : e.clientX
offsety=ie4? event.clientY : e.clientY

tempx=parseInt(crossobj.style.left)
tempy=parseInt(crossobj.style.top)

dragapproved=true
document.onmousemove=drag_drop
}
}
document.onmousedown=initializedrag
document.onmouseup=new Function("dragapproved=false")

////drag drop functions end here//////

function hidebox(){
if (ie4||ns6)
crossobj.style.visibility="hidden"
else if (ns4)
document.showimage.visibility="hide"
}

</script>

<div id="showimage" style="position:absolute;width:250px;left:250px;top:250px">

<table border="0" width="250" bgcolor="#000080" cellspacing="0" cellpadding="2">
  <tr>
    <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0"
    height="36px">
      <tr>
        <td id="dragbar" style="cursor:hand; cursor:pointer" width="100%" onMousedown="initializedrag(event)"><ilayer width="100%" onSelectStart="return false"><layer width="100%" onMouseover="dragswitch=1;if (ns4) drag_dropns(showimage)" onMouseout="dragswitch=0"><font face="Verdana"
        color="#FFFFFF"><strong><small>Announcement Box</small></strong></font></layer></ilayer></td>
        <td style="cursor:hand"><a href="#" onClick="hidebox();return false"><img src="close.gif" width="16px"
        height="14px" border=0></a></td>
      </tr>
      <tr>
        <td width="100%" bgcolor="#FFFFFF" style="padding:4px" colspan="2">

<!-- PUT YOUR CONTENT BETWEEN HERE -->

Testing 1 2 3

<!-- END YOUR CONTENT HERE -->

</td>
      </tr>
    </table>
    </td>
  </tr>
</table>
</div>


<?php
}// function
?>
